package com.aloha.minio.config;

import com.aloha.minio.service.impl.MinioServiceImpl;
import io.minio.MinioClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author DaiZhiHeng
 * @description Minio配置类
 * @date 2023/4/5 14:35
 */
@Configuration
@ConditionalOnClass(MinioServiceImpl.class)
@EnableConfigurationProperties(MinioConfigProperties.class)
public class MinioConfig {

    @Bean
    public MinioClient minioClient(MinioConfigProperties minioConfigProperties) {
        return MinioClient
                .builder()
                .endpoint(minioConfigProperties.getEndpoint())
                .credentials(minioConfigProperties.getAccessKey(), minioConfigProperties.getSecretKey())
                .build();
    }
}
